<?php
	/**
	* Update logs
	* 10/01/2010        immanuel192         Uncomment exponent_flow_set
	*                                       In version AG VN, we dont need fancybox
	*                                       Fix error get news image path
	* Feb 11, 2011      trungdt             Implement with SEO module
	*                                       Second parameter is ID or internal name
	*                                       Change datetime to new format to look like hoithanh.com
	*/


	if (!defined("EXPONENT")) exit("");
	$id ="";
	$news=null;
	if (isset($_GET['id']))
	{
		$id=$_GET['id'];
		$id=htmlspecialchars($id,ENT_QUOTES);
		if (!is_int($id))
		{
			$news = $db->selectObject("newsitem","internal_name = '{$id}'");
		}
		else{
			$news = $db->selectObject("newsitem","id= {$id}");
		}
	}
	
	
	if ($news != null) {
		exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_ACTION);
		$loc = unserialize($news->location_data);
		$iloc = $loc;
		$iloc->int = $news->id;

		$news->permissions = array(
		"edit_item"=>((exponent_permissions_check("edit_item",$loc) || exponent_permissions_check("edit_item",$iloc)) ? 1 : 0),
		"delete_item"=>((exponent_permissions_check("delete_item",$loc) || exponent_permissions_check("delete_item",$iloc)) ? 1 : 0),
		"administrate"=>((exponent_permissions_check("administrate",$loc) || exponent_permissions_check("administrate",$iloc)) ? 1 : 0)
		);
		$file = $db->selectObject("file","id=".$news->file_id);
		if(!empty($file)){
			$news->image = BASE_URL . "/".$file->directory.'/'.$file->filename;
		}
		else
			$news->image = "";
			
		$news->real_posted = ($news->publish != 0 ? $news->publish : $news->posted);
		//$news->image = $file->directory.'/'.$file->filename;
		// for date
		$date_translate = exponent_lang_loadFile('subsystems/forms/controls/yuicalendarcontrol.php');
		$date_time=0;
		if ($news->edited == 0)
			$date_time=$news->real_posted;
		else
			$date_time=$news->edited;
		$datetime = date('l, F d, o g:i a', $date_time);
		
		// If the language is english, use the default language of yui calendar
		if (USE_LANG != 'eng_US') {
			// Translate days of the week
			// thứ
			$datetime=$date_translate[strtolower(substr(date('l',$date_time),0,2))].", ";
			// ngày
			$datetime.=date('d',$date_time)." ";
			// tháng
			$datetime.=$date_translate[strtolower(date('F',$date_time))]." ";
			// năm
			$datetime.=" năm ".date('o',$date_time)." - ";
			$datetime.=date('g:i',$date_time)." ";
			// am - pm
			$datetime.=$date_translate[strtolower(date('a',$date_time))];
		}
		$news->datetime=$datetime;

		// for poster name
		$temp=$db->selectObject("user","id = " . $news->poster);
		$news->poster_name = "";
		if ($temp)
		{
			$news->poster_name = $temp-> firstname . $temp->lastname;
		}

		$view = (isset($_GET['view']) ? $_GET['view'] : "_viewSingle");
		
		$template = new template("newsmodule",$view,$loc);
		
		$template->assign("newsitem",$news);
		$template->assign("loc",$loc);
		// register page title
		_ab_theme_action_register_title($news->title." - ".exponent_lang_getText("news_view_page_title"));
		$template->output();
	} else {
		echo SITE_404_HTML;
	}

?>
